//
//  BookDetailViewController.m
//  XML
//
//  Created by iPhone SDK Articles on 11/23/08.
//  Copyright 2008 www.iPhoneSDKArticles.com.
//

#import "BookDetailViewController.h"
#import "Sequencer.h"
#import "PlayView.h"
#import "PlayerView.h"


@implementation BookDetailViewController
@synthesize aSequencer;

/*
// Override initWithNibName:bundle: to load the view using a nib file then perform additional customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically.
- (void)loadView {
}
*/
-(IBAction) Playbtn_Clicked:(id)play{
	NSString *serverIP = aServerIP.ServerIP;
	NSString *server = [[NSString alloc] initWithFormat:@"http://%@:41402/request.html?action=execute",serverIP];
	//create the request
	NSURL *url = [NSURL URLWithString:server];
	NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
	
	[request setHTTPMethod:@"GET"];
	[request setCachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData];
	NSURLConnection *connection = [[NSURLConnection alloc]
								   initWithRequest:request	
								   delegate:self];
	NSLog(server, connection);
}

// Implement viewDidLoad to do additional setup after loading the view.
- (void)viewDidLoad {
    [super viewDidLoad];
	
	self.title = @"Sequencer Detail";
}

- (void)viewWillAppear:(BOOL)animated {
	[super viewWillAppear:animated];
	
	[tableView reloadData];
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
    // Release anything that's not essential, such as cached data
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }
	
	switch(indexPath.section)
	{
		case 0:
			cell.text = aSequencer.Sequence;
			NSString *serverIP = aServerIP.ServerIP;
			NSString *server = [[NSString alloc] initWithFormat:@"http://%@:41402/vixen/command.html?action=retrieve&scope=remote&filename=%@", serverIP, aSequencer.Sequence];
			//create the request
			NSURL *url = [NSURL URLWithString:server];
			NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
			
			[request setHTTPMethod:@"POST"];
			[request setCachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData];
			NSURLConnection *connection = [[NSURLConnection alloc]
										   initWithRequest:request	
										   delegate:self];
			NSLog(server, connection);
			break;
			

	}
	
	return cell;
}

- (NSString *)tableView:(UITableView *)tblView titleForHeaderInSection:(NSInteger)section {
	
	NSString *sectionName = nil;
	
	switch(section)
	{
		case 0:
			sectionName = [NSString stringWithString:@"Name"];
			break;
	}
	
	return sectionName;
}


- (void)dealloc {
	
	[aSequencer release];
	[tableView release];
    [super dealloc];
}


@end
